package com.wyh.utils.g3utils;

import cn.hutool.jwt.Claims;
import com.auth0.jwt.JWT;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.wyh.common.constant.Constants;
import com.wyh.common.utils.JwtUtil;
import com.wyh.common.utils.TokenUtils;
import com.wyh.domain.dto.g3dto.G3BillingItemsDto;
import com.wyh.domain.dto.gfive.LoginUser;
import com.wyh.domain.po.g3po.BillingItems;
import com.wyh.security.gfive.service.TokenService;
import org.apache.commons.lang3.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

public class BillingItemsUtils {

    private static TokenService tokenService;

    //得到formula中的id
    public static List<Integer> StringToList(String formula) {
        List<Integer> ids = new ArrayList<>();
        String[] idArray = formula.split(",");
        for (String id : idArray) {
            ids.add(Integer.parseInt(id));
        }
        return ids;
    }

    //查询id列表中数字是否存在
    public static int findNumberIndex(List<Integer> numbers, Integer target) {
        for (int i = 0; i < numbers.size(); i++) {
            if (numbers.get(i).equals(target)) {
                return i;
            }
        }
        return -1;
    }

    public static String findRemoveAndJoinNumbers(List<Integer> numbers, Integer target) {
        List<Integer> result = new ArrayList<>(numbers); // 创建一个结果列表，初始化为原始列表的拷贝

        if (result.contains(target)) {
            result.remove(target); // 如果 target 存在于列表中，则删除对应的元素
        }

        StringBuilder joinedNumbers = new StringBuilder();
        for (int i = 0; i < result.size(); i++) {
            joinedNumbers.append(result.get(i)); // 将数字拼接到 StringBuilder 中

            if (i != result.size() - 1) {
                joinedNumbers.append(","); // 在非最后一个数字后添加英文逗号
            }
        }

        return joinedNumbers.toString(); // 将 StringBuilder 转换为 String 并返回
    }


    //用于修改和新增时对BillingItems表的操作
    public static BillingItems getBillingItems(G3BillingItemsDto dto){
        BillingItems billingItems = new BillingItems();
        billingItems.setId(dto.getId());
        billingItems.setParentid(dto.getParentid());
        billingItems.setName(dto.getName());
        billingItems.setType(dto.getType());
        billingItems.setFormula(dto.getFormula());
        billingItems.setFeeclassificationid(dto.getFeeclassificationid());
        billingItems.setStatisticaltypeid(dto.getStatisticaltypeid());
        billingItems.setSpecialdeposit(dto.getSpecialdeposit());
        billingItems.setSpecialName(dto.getSpecialName());
        billingItems.setState(1);
        billingItems.setDeposittypeid(dto.getDeposittypeid());
        billingItems.setThreemetertypeid(dto.getThreemetertypeid());
        billingItems.setUserid(dto.getUserid());
        billingItems.setUpdatetime(new Timestamp(System.currentTimeMillis()));

        return billingItems;
    }



}
